Solving 10385 - Duathlon (Ternary search)
[and.git] / 270 - Lining Up / 270.2.cpp
blob90dec4fd25168edf163bc3bc969751241ec8a1e0
1 /*
2 Problem: 270 - Lining up
3 Andrés Mejía-Posada (andmej@gmail.com)
5 */
6 using namespace std;
7 #include <algorithm>
8 #include <iostream>
9 #include <iterator>
10 #include <sstream>
11 #include <fstream>
12 #include <cassert>
13 #include <climits>
14 #include <cstdlib>
15 #include <cstring>
16 #include <string>
17 #include <cstdio>
18 #include <vector>
19 #include <cmath>
20 #include <queue>
21 #include <deque>
22 #include <stack>
23 #include <list>
24 #include <map>
25 #include <set>
27 #define D(x) cout << #x " is " << x << endl
29 struct point{
30 int x, y;
31 point(int x=0, int y=0) : x(x), y(y) {}
34 void simplify(pair<int, int> &p){
35 #define x first
36 #define y second
37 assert(p.x != 0 || p.y != 0);
38 if (p.y == 0){
39 p.x = 1;
40 return;
42 if (p.x == 0){
43 p.y = 1;
44 return;
46 int sign = ((p.x<0)^(p.y<0) ? -1 : 1);
47 p.x = abs(p.x), p.y = abs(p.y);
48 int g = __gcd(p.x, p.y);
49 if (g) p.x /= g, p.y /= g;
50 p.x *= sign;
51 #undef x
52 #undef y
55 int main(){
56 int casos;
57 cin >> casos;
58 string s;
59 getline(cin, s), getline(cin, s);
60 while (casos--){
61 vector<point> p;
62 while (getline(cin, s) && s != ""){
63 point _;
64 sscanf(s.c_str(), "%d %d", &_.x, &_.y);
65 p.push_back(_);
68 int x = 0;
69 map<pair<int, int>, int> cnt;
70 const int n = p.size();
71 for (int i=0; i<n; ++i){
72 for (int j=i+1; j<n; ++j){
73 pair<int, int> slope(p[j].y - p[i].y, p[j].x - p[i].x);
74 simplify(slope);
75 map<pair<int, int>, int>::iterator i = cnt.find(slope);
76 if (i != cnt.end()) x = max(x, ++i->second);
77 else x = max(x, cnt[slope] = 2);
80 cout << (int)((1 + sqrt(1 + 8*x))/2) << endl;
81 if (casos > 0) cout << endl;
83 return 0;